package tech.kunyuan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.kunyuan.domain.Code;
import tech.kunyuan.service.CodeService;
import tech.kunyuan.utils.RedisUtils;

import java.util.List;

/**
 * Description:
 *
 * @Author: ky
 * DateTime: 2022-10-20 10:24
 */

@RestController
@RequestMapping("/code")
public class CodeController {
    @Autowired
    private CodeService codeService;
    @Autowired
    private RedisUtils redisUtils;

    @GetMapping
    public List<Code> list(){

        String key = "redis-test-code";
        Code resources = new Code();
        List<Code> list = codeService.queryAll(resources);
        redisUtils.set(key, list);
        return list;

        /*List<Code> result = redisUtils.getList(key, Code.class);
        if(result != null && !result.isEmpty()){
            System.out.println("get");
            System.out.println(result);
            return result;
        }else {

            System.out.println("set");
            Code resources = new Code();
            List<Code> list = codeService.queryAll(resources);
            redisUtils.set(key, list);
            return list;
        }*/
    }


    @GetMapping("/{id}")
    public Code detail(@PathVariable Integer id){
        return codeService.queryOne(id);
    }
}
